﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Entity;

namespace School.SystemManage.WebPages.Teacher
{
    public partial class LadyDeedsList : Base.PermissionBasePage
    {
        TechnologySchoolEntities db = new TechnologySchoolEntities();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int total = db.LadyInfo.Count();
                AspNetPager1.RecordCount = total;
                BindData();
            }
        }

        private void BindData()
        {           
            rep_list.DataSource = DAL.PagerHelper.GetPagerData("LadyInfo", "lid,imgPath,name,rjxe,xrzw,zc,xl", "name",
                AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, "");
            rep_list.DataBind();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }

        protected void rep_list_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                HiddenField hf = (HiddenField)e.Item.FindControl("hf");
                int lid = int.Parse(hf.Value);

                var data = db.LadyInfo.FirstOrDefault(l => l.lid == lid);
                if (data != null)
                {
                    db.DeleteObject(data);
                }

                if (db.SaveChanges() > 0)
                {
                    BindData();
                }
                else
                {
                    lblMsg.Text = "删除失败！";
                }
            }
        }

        #region 操作权限控制

        public override void SetEditDisable()
        {
            base.SetEditDisable();

            btnAddItem.Visible = false;
            foreach (RepeaterItem item in rep_list.Items)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    LinkButton linkDelete = (LinkButton)item.FindControl("LinkButton2");
                    linkDelete.Visible = false;
                    HtmlGenericControl linkEdit = (HtmlGenericControl)item.FindControl("btnEditContainer");
                    linkEdit.Visible = false;
                }
            }

        }

        public override void SetReviewDisable()
        {
            base.SetReviewDisable();
        }

        public override void SetViewDisable()
        {
            base.SetViewDisable();
        }

        #endregion
    }
}
